﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace WPFLoaders
{
    [ValueConversion(typeof(int), typeof(double), ParameterType = typeof(double))]
    public class MultiplyIntConverter : IValueConverter
    {
        public static MultiplyIntConverter Instance
        {
            get { return new MultiplyIntConverter(); }
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var integer = (int) value;
            var multiplier = (double)System.Convert.ChangeType(parameter, typeof(double));

            return integer*multiplier;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var result = (double) value;
            var multiplier = (double)System.Convert.ChangeType(parameter, typeof(double));
            return (int) (result/multiplier);
        }
    }
}
